#include "CloudCtrler.h"
#include "util/Util.h"
#include "communication/DataPacket.h"
CloudCtrler::CloudCtrler(Assembler* pAssm):
MasterControl(pAssm),
m_socket(this)
{

}

CloudCtrler::~CloudCtrler()
{

}


ErrorCode CloudCtrler::Init()
{
	bool bOk = m_config.SetSource("./config/cloudctrler.cfg");
	if( !bOk )
	{
		_LOG("Can't Open cloudctrler.cfg");
		return eFailed;
	}
	std::string strAddress	= m_config.GetStringDefault("SERVER","ADDRESS","");
	std::string strUserName = m_config.GetStringDefault("SERVER","USER","guest");
	std::string strPwd		= m_config.GetStringDefault("SERVER","PWD","guest");
	bool bIsOk = m_socket.InitSession(strAddress.c_str(),strUserName.c_str(),strPwd.c_str(),Session::eTCP);
	if( !bIsOk )
	{
		return eFailed;
	}
	_LOG("CloudCtrler Init Success...");
	this->OnReady(0);
	return eOK;
}


ErrorCode CloudCtrler::PushData(char* pData, uint32 nLen)
{
	m_socket.OutPacket(0,nLen,pData);
	return eOK;
}
ErrorCode CloudCtrler::OnReceive( DataPacket& pack )
{
	
	return eOK;
}


ErrorCode CloudCtrler::Update(uint32 dtTime)
{
	m_socket.Update( dtTime );
	return eOK;
}

void CloudCtrler::OnReady(uint32 errCode)
{
	MasterControl::OnReady( errCode );
	_LOG("CloudCtrler Ready![%d]",errCode);
}